﻿//
// GNS_PlayerCritValue.cpp
// MobileManageSys
//
// Created by mr.l on 16/1/14.
//
//

#include "GNS_PlayerCritValue.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "GNS_PlayerMgr.h"
USING_NS_CC;
using namespace cocostudio::timeline;
using namespace ui;

#define winsize Director::getInstance()->getVisibleSize()

GNS_PlayerCritValue::GNS_PlayerCritValue()
{
    pGNS_PlayerCritValue=0;
}

GNS_PlayerCritValue::~GNS_PlayerCritValue()
{
    
}

GNS_PlayerCritValue* GNS_PlayerCritValue::createLayer()
{
    auto pGNS_PlayerCritValue = GNS_PlayerCritValue::create();
    auto pScene = Director::getInstance()->getRunningScene();
    if (!pScene)
        return 0;
    pScene->addChild(pGNS_PlayerCritValue);
    return pGNS_PlayerCritValue;
}

bool GNS_PlayerCritValue::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    return true;
}
void GNS_PlayerCritValue::SetNodeName(std::string CsbName)
{
    pGNS_PlayerCritValue = CSLoader::createNode(CsbName);
    pGNS_PlayerCritValue->setContentSize(winsize);
    ui::Helper::doLayout(pGNS_PlayerCritValue);
    addChild(pGNS_PlayerCritValue,11);
    GNS_PlayerMgr::getInstance()->_NodeChildVec.pushBack(pGNS_PlayerCritValue);
    auto pBackBtn = static_cast<Button*>(pGNS_PlayerCritValue->getChildByName("PlayerCritValueBackBtn"));
    pBackBtn->setTag(10);
    pBackBtn->addTouchEventListener(CC_CALLBACK_2(GNS_PlayerCritValue::BtnCallBack, this));
}

void GNS_PlayerCritValue::BtnCallBack(cocos2d::Ref *pSender, ui::Widget::TouchEventType type){
    if (type==ui::Widget::TouchEventType::ENDED) {
        auto pButton = (Button*)pSender;
        int BtnTag = pButton->getTag();
        switch (BtnTag) {
            case 10:
            {
                if (GNS_PlayerMgr::getInstance()->_NodeChildVec.size()!=0) {
                    GNS_PlayerMgr::getInstance()->_NodeChildVec.clear();
                    this->removeAllChildrenWithCleanup(true);
                    this->getParent()->removeChild(this);
                }
                //auto SystemNode=GNS_PlayerMgr::getInstance()->_NodeHallVec.at(0);
                //SystemNode->setVisible(true);

				GNS_NodeMgr::getInstance()->setMenuVisible("SystemMgr", true);
                break;
            }
            default:
                break;
        }
    }
}
